﻿// -----------------------------------------------------------------------
// <copyright file="Duck.cs" company="Microsoft">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace Cspl.AnimalFight.Lib.Data
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Cspl.AnimalFight.Lib.Interfaces;
    using Cspl.AnimalFight.Lib.EventHandlers;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class Duck : AnimalBase, IAttack, IAttackable
    {
        public event AttackDelegate AttackEvent;

        public void Attack(string targetName)
        {
            if (this._hasEscaped)
            {
                Console.WriteLine("{0} can not attack because {0} has escaped",this.Name);
            }
            else if (this._isDead)
            {
                Console.WriteLine("{0} can not attack because {0} is already died", this.Name);
            }
            else
            {
                if (AttackEvent != null)
                {
                    AttackEventHandler e = new AttackEventHandler
                    {
                        AnimalTargetName = targetName,
                        AP = this.AP
                    };

                    AttackEvent(this, e);
                }
            }
        }

        public override void Escape()
        {
            this.HasEscaped = true;
            Console.WriteLine("Duck has escaped.");
        }

        public void Attacked(int ap)
        {
            if (this._hasEscaped)
            {
                Console.WriteLine("{0} has escaped. Cannot be attacked.", this.Name);
            }
            else if (this._isDead)
            {
                Console.WriteLine("{0} is already dead. Cannot be attacked.", this.Name);
            }
            else
            {
                Console.WriteLine("{0} is being attacked. Original HP={1}", this.Name, this.HP);

                this.HP -= (ap - this.DP);

                Console.WriteLine("HP is decreased -{0}", ap - this.DP);

                if (this.HP <= 0)
                {
                    Console.WriteLine("The {0} is dead.", this.Name);
                    this.IsDead = true;
                }
            }
        }
    }
}
